using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VBKOMBI
    {
        public DataRow Convert2BKOMBI(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryBKOMBI(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["BKMANDANT"] = " ".PadRight(2 ); 
         dwReturn["BKART"] = " ".PadRight(20 ); 
         dwReturn["BKVAR"] = " ".PadRight(2 ); 
         dwReturn["BKFARBE"] = " ".PadRight(10 ); 
         dwReturn["BKPOS"] = " ".PadRight(2 ); 
         dwReturn["BKAENDZL"] = " ".PadRight(0 ); 
         dwReturn["BKAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["BKAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["BKNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["BKNEUDAT"] = " ".PadRight(0 ); 
         dwReturn["BKSRFNR"] = " ".PadRight(15 ); 
         dwReturn["BKFDZ"] = " ".PadRight(0 ); 
         dwReturn["BKBAHN"] = " ".PadRight(1 ); 
         dwReturn["BKKETTE"] = " ".PadRight(1 ); 
         dwReturn["BKLLEIST"] = " ".PadRight(4 ); 
         dwReturn["BKLLZUL"] = " ".PadRight(1 ); 
         dwReturn["BKRLEIST"] = " ".PadRight(4 ); 
         dwReturn["BKRLZUL"] = " ".PadRight(1 ); 
         dwReturn["BKFILLER"] = " ".PadRight(32 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapBKOMBI(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveBKOMBI(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryBKOMBI(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapBKOMBI(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertBKOMBI(dwLocal, ITXDBVERSION);
            }
            UpdateBKOMBI(dwLocal);
        }
        public void InsertBKOMBI(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO BKOMBI(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryBKOMBI(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM BKOMBI WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM BKOMBI  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "BKOMBI";
            Return = Result;
            return Return;
        }
        public void DeleteBKOMBI(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM BKOMBI   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateBKOMBI(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE BKOMBI SET "
                    +"BKMANDANT= :BKMANDANT,"
                    +"BKART= :BKART,"
                    +"BKVAR= :BKVAR,"
                    +"BKFARBE= :BKFARBE,"
                    +"BKPOS= :BKPOS,"
                    +"BKAENDZL= :BKAENDZL,"
                    +"BKAENDBEN= :BKAENDBEN,"
                    +"BKAENDDAT= :BKAENDDAT,"
                    +"BKNEUBEN= :BKNEUBEN,"
                    +"BKNEUDAT= :BKNEUDAT,"
                    +"BKSRFNR= :BKSRFNR,"
                    +"BKFDZ= :BKFDZ,"
                    +"BKBAHN= :BKBAHN,"
                    +"BKKETTE= :BKKETTE,"
                    +"BKLLEIST= :BKLLEIST,"
                    +"BKLLZUL= :BKLLZUL,"
                    +"BKRLEIST= :BKRLEIST,"
                    +"BKRLZUL= :BKRLZUL,"
                    +"BKFILLER= :BKFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("BKMANDANT", OracleType.NVarChar).Value = dwData["BKMANDANT"].ToString(); 
          or1.Parameters.Add("BKART", OracleType.NVarChar).Value = dwData["BKART"].ToString(); 
          or1.Parameters.Add("BKVAR", OracleType.NVarChar).Value = dwData["BKVAR"].ToString(); 
          or1.Parameters.Add("BKFARBE", OracleType.NVarChar).Value = dwData["BKFARBE"].ToString(); 
          or1.Parameters.Add("BKPOS", OracleType.NVarChar).Value = dwData["BKPOS"].ToString(); 
          or1.Parameters.Add("BKAENDZL", OracleType.NVarChar).Value = dwData["BKAENDZL"].ToString(); 
          or1.Parameters.Add("BKAENDBEN", OracleType.NVarChar).Value = dwData["BKAENDBEN"].ToString(); 
          or1.Parameters.Add("BKAENDDAT", OracleType.NVarChar).Value = dwData["BKAENDDAT"].ToString(); 
          or1.Parameters.Add("BKNEUBEN", OracleType.NVarChar).Value = dwData["BKNEUBEN"].ToString(); 
          or1.Parameters.Add("BKNEUDAT", OracleType.NVarChar).Value = dwData["BKNEUDAT"].ToString(); 
          or1.Parameters.Add("BKSRFNR", OracleType.NVarChar).Value = dwData["BKSRFNR"].ToString(); 
          or1.Parameters.Add("BKFDZ", OracleType.NVarChar).Value = dwData["BKFDZ"].ToString(); 
          or1.Parameters.Add("BKBAHN", OracleType.NVarChar).Value = dwData["BKBAHN"].ToString(); 
          or1.Parameters.Add("BKKETTE", OracleType.NVarChar).Value = dwData["BKKETTE"].ToString(); 
          or1.Parameters.Add("BKLLEIST", OracleType.NVarChar).Value = dwData["BKLLEIST"].ToString(); 
          or1.Parameters.Add("BKLLZUL", OracleType.NVarChar).Value = dwData["BKLLZUL"].ToString(); 
          or1.Parameters.Add("BKRLEIST", OracleType.NVarChar).Value = dwData["BKRLEIST"].ToString(); 
          or1.Parameters.Add("BKRLZUL", OracleType.NVarChar).Value = dwData["BKRLZUL"].ToString(); 
          or1.Parameters.Add("BKFILLER", OracleType.NVarChar).Value = dwData["BKFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
